From: Jyrki Gadinger Date: Tue, 15 Apr 2025 08:13:14 +0000 (+0200) Subject: fix(theme): correct dark/light mode check on Win10 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2^2~25^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=c9f0f4263eede1e1d986a0131c8b296ce72c593a;p=nextcloud-desktop.git fix(theme): correct dark/light mode check on Win10 `Utility::registryGetKeyValue` returns an invalid QVariant should the key not exist -- which is the case if that switch has never been toggled before. --> Fix this by ensuring the QVariant is valid, and only then try to convert it to a bool. Signed-off-by: Jyrki Gadinger --- diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 9e90a0002..f1a7108bd 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -1032,10 +1032,11 @@ bool Theme::darkMode() const #ifdef Q_OS_WIN static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); - if (!isWindows11OrGreater() && - Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) && - !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) { - return true; + if (!isWindows11OrGreater() && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey)) { + if (const auto keyVariant = Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")); + keyVariant.isValid() && !keyVariant.toBool()) { + return true; + } } #endif return isDarkFromStyle();